package com.pucheng.bracelet.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.pucheng.bracelet.R;
import com.pucheng.bracelet.app.util.DatetimeUtil;
import com.pucheng.bracelet.data.bean.SleepBean;

public class SleepScatterView extends LinearLayout {

    private TextView tvStartTime;
    private TextView tvEndTime;
    private SleepProgressBar pbSleep;

    public SleepScatterView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public SleepScatterView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context);
    }

    public SleepScatterView(Context context) {
        super(context);
        init(context);
    }

    public SleepScatterView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        init(context);
    }

    private void init(Context context) {
        View view = inflate(context, R.layout.layout_sleep_scatter, this);
        tvStartTime = view.findViewById(R.id.tv_sleep_start_time);
        tvEndTime = view.findViewById(R.id.tv_sleep_end_time);
        pbSleep = view.findViewById(R.id.pb_sleep);
    }

    public void setSleepInfo(SleepBean bean){
        pbSleep.setSleepInfo(bean);
        tvStartTime.setText(DatetimeUtil.formatDate(bean.getTimestamp(),DatetimeUtil.DATE_PATTERN_HHMM));
        tvEndTime.setText(DatetimeUtil.formatDate(bean.getTimestamp()+bean.getTotalTime()*60,DatetimeUtil.DATE_PATTERN_HHMM));
    }

    public void setTextColor(int resId){
        tvStartTime.setTextColor(getResources().getColor(resId));
        tvEndTime.setTextColor(getResources().getColor(resId));
    }
}
